package juc.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author fangbin
 * @desc 演示可重入性
 * @date 2020/5/30 7:59
 */
public class RecursionDemo {

    private static ReentrantLock lock = new ReentrantLock();

    private static void asccessResource(){
        System.out.println("对资源进行处理。。。。");
        lock.lock();
        try{
            int holdCount = lock.getHoldCount();
            System.out.println("获得锁次数："+holdCount);
            if(holdCount<5){
                asccessResource();
                System.out.println("获得锁次数："+holdCount);
            }

        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        RecursionDemo.asccessResource();
    }
}
